package com.tesis_2.UI;

import java.util.Date;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLLocales;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MORestaurant;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class UIRegistrarLocal extends Activity {

	private int nRest;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uiregistrar_local);
		Bundle b = getIntent().getExtras();
		nRest = b.getInt("RestId");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uiregistrar_local, menu);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optGuardar_registrar_local:
	        	
			
				saveLocal();
			
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	}

	public void saveLocal()
	{
		String nombre = ((EditText) findViewById(R.id.txtNombre_registrar_local)).getText().toString();
		String descr = ((EditText) findViewById(R.id.txtDescr_registrar_local)).getText().toString();
		String dir1 = ((EditText) findViewById(R.id.txtDireccion_registrar_local)).getText().toString();
		String dir2 = ((EditText) findViewById(R.id.txtDireccion_registrar_local)).getText().toString();
		String telef1 = ((EditText) findViewById(R.id.txtTelefono1_registrar_local)).getText().toString();
		String telef2 = ((EditText) findViewById(R.id.txtTelefono2_registrar_local)).getText().toString();
		String capacity = ((EditText) findViewById(R.id.txtCapacidad_registrar_local)).getText().toString();
		
		MOLocal objLocal = new MOLocal();
		
		objLocal.setName(nombre.replace(" ", "%20"));
		objLocal.setDescr(descr.replace(" ", "%20"));
		objLocal.setAddr1(dir1.replace(" ", "%20"));
		objLocal.setAddr2(dir2.replace(" ", "%20"));
		objLocal.setPhone1(telef1.replace(" ", "%20"));
		objLocal.setPhone2(telef2.replace(" ", "%20"));
		objLocal.setCapacity(Integer.parseInt((capacity.replace(" ", "%20"))));
		objLocal.setRest_id(nRest);
		
	
		try {
			objLocal = BLLocales.createLocal(objLocal);
			finish();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
